import matplotlib.pyplot as plt
import numpy as np

# 数据
labels = ['Q1', 'Q2', 'Q3', 'Q4']
product_a = [50, 60, 55, 70]
product_b = [30, 40, 45, 50]
product_c = [20, 30, 35, 40]

# 错误数据
product_a_error = [5, 6, 4, 5]
product_b_error = [3, 4, 3, 3]
product_c_error = [2, 3, 2, 4]

x = np.arange(len(labels))  # 标签位置

# 创建有误差棒的柱形图
fig, ax = plt.subplots()
ax.bar(x - 0.2, product_a, yerr=product_a_error, capsize=5, label='Product A', color='skyblue', edgecolor='black')
ax.bar(x, product_b, yerr=product_b_error, capsize=5, label='Product B', color='lightgreen', edgecolor='black')
ax.bar(x + 0.2, product_c, yerr=product_c_error, capsize=5, label='Product C', color='lightcoral', edgecolor='black')

# 设置标签和标题
ax.set_xlabel('Quarter')
ax.set_ylabel('Sales')
ax.set_title('Sales by Product with Error Bars')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()

plt.rcParams['font.sans-serif']=['SimHei']

plt.show()
